import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import Unocss from "unocss/vite";
import path from "path";

export default defineConfig(({ command, mode }) => {
  const env = loadEnv(mode, process.cwd());
  return {
    plugins: [vue(), Unocss()],
    resolve: {
      // 配置路径别名
      alias: {
        "@": path.resolve("./src"),
      },
    },
    server: {
      host: "0.0.0.0",
      port: 8989,
      hmr: true,
      open: true,
      proxy: {
        // 代理跨域
        [env.VITE_WEB_BASE_API]: {
          target: env.VITE_SERVER,
          rewrite: (path) =>
            path.replace(new RegExp("^" + env.VITE_WEB_BASE_API), ""),
          changeOrigin: true,
        },
      },
    },
  };
});
